package net.dgg.rz.production.controller;

import net.dgg.framework.tac.utils.bean.DggRestResponse;
import net.dgg.framework.tac.utils.exception.DggBaseException;
import net.dgg.framework.tac.utils.web.commmon.DggBaseController;
import net.dgg.iboss.base.service.CmsService;
import net.dgg.iboss.base.util.CustomerNumberEncryptionUtil;
import net.dgg.iboss.base.util.DesUtil;
import net.dgg.rz.common.constant.ModuleCodeConstant;
import net.dgg.rz.common.constant.ScProductConstant;
import net.dgg.rz.common.constant.SystemCommonConstant;
import net.dgg.rz.common.excption.CommonExcption;
import net.dgg.rz.common.service.CommonMangerExtService;
import net.dgg.rz.common.utils.*;
import net.dgg.rz.production.dao.ProductNodeDao;
import net.dgg.rz.production.dao.ProductNodeFlowDao;
import net.dgg.rz.production.dao.ProductOrderDao;
import net.dgg.rz.production.entity.ProductOrder;
import net.dgg.rz.production.entity.dto.ProductOrderDto;
import net.dgg.rz.production.entity.dto.UploadWjOrderDto;
import net.dgg.rz.production.exception.ProductOrderExcption;
import net.dgg.rz.production.service.AllOrderService;
import net.dgg.rz.production.service.ProductOrderService;
import net.dgg.tmd.foundation.platform.common.util.TranslateUtil;
import net.dgg.tmd.foundation.platform.org.dao.OrgRecorderDAO;
import net.dgg.tmd.foundation.platform.session.SessionManager;
import net.dgg.tmd.foundation.platform.user.entity.UserDTO;
import net.dgg.tmd.foundation.platform.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 订单controller
 * Created by cuipeng on 2018/12/19.
 */
@Controller
@RequestMapping("/all_order")
public class AllOrderController extends DggBaseController {

    private final static String PATH_PREFIX = "/all_order";
    @Autowired
    private ProductNodeFlowDao productNodeFlowDao;

    @Autowired
    private ProductNodeDao productNodeDao;

    @Autowired
    private CommonMangerExtService commonMangerExtService;

    @Autowired
    private SessionManager sessionManager;

    @Autowired
    private AllOrderService allOrderService;

    @Autowired
    private DesUtil desUtil;

    @Autowired
    private TranslateUtil translateUtil;

    @Autowired
    private ProductOrderDao productOrderDao;

    @Autowired
    private CmsService cmsService;

    @Autowired
    private UserService userService;

    @Autowired
    private OrgRecorderDAO orgRecorderDAO;

    @Autowired
    private ProductOrderService productOrderService;

    @Autowired
    DataPermissionUtils dataPermissionUtils;


    /**
     * 全部订单列表
     *
     * @param model
     * @param status 状态
     * @return
     */
    @RequestMapping(value = "/index")
    public String allScOrder(Model model, String status) {
       /* List<ProductNode> listNode = new ArrayList<>();
        //查询出当前登陆人的事业部id
        Map orgMap = commonMangerExtService.findBusDeptById(sessionManager.getCurrentUser().getOrgId());
        if (orgMap != null && orgMap.size() != 0) {
            Map map = new HashMap();
            Map mapNode = new HashMap();
            StringBuilder ids = new StringBuilder();
            //根据事业部的id查询出改事业部配置流程节点ids
            map.put("deptIds", orgMap.get("id"));
            if (null == map.get("orderColumn")) {
                map.put("orderDir", "desc");
                map.put("orderColumn", "updateTime");
            }
            List<ProductNodeFlow> productNodeFlowList = productNodeFlowDao.query(map);
            if (productNodeFlowList.size() > 0) {
                for (ProductNodeFlow productNodeFlow : productNodeFlowList) {
                    if (ids.length() > 0) {//该步即不会第一位有逗号，也防止最后一位拼接逗号！
                        ids.append(",");
                    }
                    ids.append(productNodeFlow.getId());
                }
                mapNode.put("deptIds", orgMap.get("id"));
                mapNode.put("processId", ids.toString().split(","));
                listNode = productNodeDao.queryByFlowProcessIds(mapNode);
            }
        }
        model.addAttribute("listNode", listNode);*/
        model.addAttribute("TIME_OUT", ScProductConstant.TIME_OUT);
        return "rzsc/order/all_order";
    }

    /**
     * 查询所有生产订单
     *
     * @param params
     * @param request
     * @return
     */
    @RequestMapping(value = "/all_Order_json")
    @ResponseBody
    public DggRestResponse allOrderResponse(@RequestParam Map params, HttpServletRequest request) {
        try {
            if (StringUtils.isNotEmpty(params.get("completeState")) && "2".equals(params.get("completeState"))) {//废单
                //statusAttr.add(ScProductConstant.RZSCORDER_STATUS08);
                params.put("target", "3");
            } else if (StringUtils.isNotEmpty(params.get("completeState")) && "3".equals(params.get("completeState"))) {//放款
                //statusAttr.add(ScProductConstant.RZSCORDER_STATUS08);
                params.put("target", "4");
            } else if (StringUtils.isNotEmpty(params.get("completeState")) && "1".equals(params.get("completeState"))) {//退单
                //statusAttr.add(ScProductConstant.RZSCORDER_STATUS06);
                params.put("target", "5");
            } else if (StringUtils.isNotEmpty(params.get("completeState")) && "4".equals(params.get("completeState"))) {
                //statusAttr.add(ScProductConstant.RZSCORDER_STATUS09);
                params.put("target", "6");
            } else if (StringUtils.isNotEmpty(params.get("completeState")) && "5".equals(params.get("completeState"))) {
                //statusAttr.add(ScProductConstant.RZSCORDER_STATUS10);
                params.put("target", "7");
            } else if (StringUtils.isNotEmpty(params.get("completeState")) && "9".equals(params.get("completeState"))) {
                //statusAttr.add(ScProductConstant.RZSCORDER_STATUS10);
                params.put("target", "9");
            } else {
                params.put("target", "8");//全部
                List<String> statusAttr = new ArrayList<>();
                if (StringUtils.isNotEmpty(params.get("statusAttr"))) {
                    statusAttr.add(params.get("statusAttr") + "");
                }
                params.put("statusArr", statusAttr);
            }
            List<ProductOrderDto> productOrderDtos = productOrderService.processingscOrderWithPage(params);
            return new DataTableResponse().data(params,productOrderDtos);
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            ExceptionUtils.error(e, PATH_PREFIX+"/all_Order_json.do", params.toString());
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 已完成订单列表页面跳转
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/completed_order_index")
    public String completeOrder(Model model) {
        model.addAttribute("TIME_OUT", ScProductConstant.TIME_OUT);
        return "rzsc/order/completed_order";
    }
    /**
     * 已完成(已退单)
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/completed_t")
    public String completedt(Model model) {
        return "rzsc/order/completed_t";
    }
    /**
     * 已完成(已废单)
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/completed_f")
    public String completedf(Model model) {
        return "rzsc/order/completed_f";
    }
    /**
     * 已完成(已放款)
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/completed_fk")
    public String completedfk(Model model) {
        return "rzsc/order/completed_fk";
    }

    /**
     * 已完成(已完结)
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/completed_wj")
    public String completedwj(Model model) {
        return "rzsc/order/completed_wj";
    }

    /**
     * 废单驳回
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/abandoned")
    public String abandoned(Model model) {
        return "rzsc/order/rejected_f";
    }

    /**
     * 退单驳回
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/back")
    @SuppressWarnings("all")
    public String back(Model model) {
        return "rzsc/order/rejected_t";
    }



    /**
     * 驳回订单列表页面跳转
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/rejected_order_index")
    @SuppressWarnings("all")
    public String rejectedOrder(Model model) {
        model.addAttribute("TIME_OUT", ScProductConstant.TIME_OUT);
        return "rzsc/order/rejected_order";
    }

    /**
     * 退单/废单恢复办理
     *
     * @param id
     * @param status
     * @return
     */
    //@AuthOpt(code = "SC_GENERAL_RESTORE")
    @RequestMapping("/restore_order")
    @ResponseBody
    public Object restoreOrder( String id, String status,@RequestParam(required = false)String userLoginName) {
        try {
            if (!status.equals(ScProductConstant.RZSCORDER_STATUS06) && !status.equals(ScProductConstant.RZSCORDER_STATUS09) && !status.equals(ScProductConstant.RZSCORDER_STATUS10)){
                return this.getFailResponse("订单状态传入错误！");
            }
            this.allOrderService.restoreOrder(id,status,userLoginName);
            return this.getSuccessResponse("success!");
        }catch (CommonExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (IllegalArgumentException e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (RuntimeException e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionUtils.error(e, PATH_PREFIX+"/restore_order.do", "id"+id+",status"+status);
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 暂缓恢复办理
     *
     * @param id
     * @return
     */
    //@AuthOpt(code = "SC_GENERAL_RESTORE")
    @RequestMapping("/restore_order_suspended")
    @ResponseBody
    public Object restoreOrderSuspended(String[] id) {
        try {
            this.allOrderService.restoreOrderSuspended(id,null);
            return this.getSuccessResponse("success!");
        }catch (CommonExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (IllegalArgumentException e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (RuntimeException e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常，请联系管理员！");
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionUtils.error(e, PATH_PREFIX+"/restore_order.do", "id"+id.toString());
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * 订单备注页面跳转
     * @return
     */
    @RequestMapping(value = "/remark_index")
    public String remarkIndex(Long id,Model model) {
        model.addAttribute("productOrder",allOrderService.getProductById(id));
        return "rzsc/order/remark";
    }


    /**
     * 订单备注
     *
     * @param id
     * @param remark
     * @return
     */
    //@AuthOpt(code = "SC_GENERAL_RESTORE")
    @RequestMapping("/remark_order")
    @ResponseBody
    public Object remarkOrder(Long id, String remark) {
        try {
            this.allOrderService.remarkOrder(id,remark,null);
            return this.getSuccessResponse("success!");
        }catch (CommonExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (IllegalArgumentException e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (RuntimeException e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常，请联系管理员！");
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionUtils.error(e, PATH_PREFIX+"/restore_order.do", "id"+id+",remark"+remark);
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }


    /**
     * 异常订单列表页面跳转
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/abnormal_order_index")
    public String abnormalOrder(Model model) {
        model.addAttribute("TIME_OUT", ScProductConstant.TIME_OUT);
        return "rzsc/order/abnormal_order";
    }



    /**
     * 异常订单移交弹框页面
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/layer_turnover_abnormal")
    public String layerTurnoverAbnormal(Model model,String ids) {
        /*Map map = new HashMap();
        map.put("level", "ORG_LEVEL_1");
        map.put("orgId", "1 ");
        List<Map> orgs = cmsService.findOrgs(map);
        model.addAttribute("orgs",orgs);*/
        model.addAttribute("ids",ids);
        return "rzsc/order/layer_turnover_abnormal";
    }

    /**
     * 根据部门ID查员工
     *
     * @param  deptId
     * @return
     */
    //@AuthOpt(code = "SC_GENERAL_RESTORE")
    @RequestMapping("/get_user_by_deptid")
    @ResponseBody
    public Object getUserByDeptId(String deptId) {
        try {
            Map params = new HashMap();
            if (StringUtils.isNotEmpty(deptId)) {
                Long organId = Long.parseLong(deptId);
                List<Long> listIds = orgRecorderDAO.findOrgIdsByPId(organId);
                if (null != listIds && listIds.size() > 0) {
                    params.put("orgIds", listIds);
                }
            }
            List<UserDTO> userList = userService.findUserDTOPage(params);
            return this.getSuccessResponse(userList);
        }catch (CommonExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (IllegalArgumentException e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (RuntimeException e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常，请联系管理员！");
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionUtils.error(e, PATH_PREFIX+"/get_user_by_deptid.do", "deptId"+deptId);
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 移交保存</p>
     * <p>@author cuipeng</p>
     * <p>@Time 2018/12/26 </p>
     * <p>@return</p>
     */
    @RequestMapping("/save_turn_over")
    @ResponseBody
    public DggRestResponse saveTurnOver(@RequestParam Map map) {
        try {
            allOrderService.saveTurnOver(map);
            return this.getSuccessResponse("操作成功!");
        }catch (CommonExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (IllegalArgumentException e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (RuntimeException e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常，请联系管理员！");
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionUtils.error(e, PATH_PREFIX+"/save_turn_over.do", map.toString());
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 跨事业部移交保存</p>
     * <p>@author cuipeng</p>
     * <p>@Time 2019/1/10 </p>
     * <p>@return</p>
     */
    @RequestMapping("/save_turn_over_org")
    @ResponseBody
    public DggRestResponse saveTurnOverOrg(String orderId,String productId) {
        try {
            allOrderService.saveTurnOverOrg(orderId,productId);
            return this.getSuccessResponse("操作成功!");
        }catch (CommonExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (IllegalArgumentException e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (RuntimeException e) {
            e.printStackTrace();
            return this.getFailResponse("系统异常，请联系管理员！");
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionUtils.error(e, PATH_PREFIX+"/save_turn_over_org.do","orderId"+ orderId+",productId"+productId);
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }



    /**
     * <p>@Description 拨打电话的查找客户信息</p>
     * <p>@author cuipeng</p>
     * <p>@Time 2018/12/28 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/find_call_info")
    @ResponseBody
    public DggRestResponse findCallInfo(Long id) {
        try {
            ValidateUtils.strNotEmpty(id, ProductOrderExcption.class, "生产订单id不能为空！");
            ProductOrder productOrder = productOrderDao.selectByPrimaryKey(id);
            ValidateUtils.strNotEmpty(productOrder, ProductOrderExcption.class, "未查询到该生产订单的信息！");
            Map<String, Object> customer = new HashMap<>();
            customer.put("id", productOrder.getId());
            customer.put("name", productOrder.getCustomerName());
            customer.put("phone", productOrder.getCustomerPhone());
            Map noMap = new HashMap();
            noMap.put("phoneStr",desUtil.decrypt(productOrder.getCustomerPhone()));
            noMap = CustomerNumberEncryptionUtil.encryptionObject(new String[]{"phoneStr"},noMap);
            customer.put("phoneStr", noMap.get("phoneStr"));
            return this.getSuccessResponse(customer);
        } catch (DggBaseException e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
            ExceptionUtils.error(ex, PATH_PREFIX+"/find_call_info.do","id"+ id);
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * <p>@Description 通过客户ID查电话</p>
     * <p>@author mqy</p>
     * <p>@Time 2018/9/13 0013 14:40 创建时间</p>
     * <p>@return</p>
     */
    @RequestMapping(value = "/find_phone_by_customer_id")
    @ResponseBody
    public DggRestResponse findPhoneByCustomerId(Long customerId) {
        try {
            ValidateUtils.strNotEmpty(customerId, ProductOrderExcption.class, "客户id不能为空！");
            String phoneByCustomerId = allOrderService.findPhoneByCustomerId(customerId);
            if (StringUtils.isNotEmpty(phoneByCustomerId)) {
                return this.getSuccessResponse(phoneByCustomerId);
            }
            return this.getFailResponse("未获取到该客户的电话号码!");
        } catch (DggBaseException e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionUtils.error(e, PATH_PREFIX+"/find_phone_by_customer_id.do","customerId"+ customerId);
            return this.getFailResponse("系统异常,请联系管理员!");
        }
    }

    /**
     * 导出(全部)
     */
    @RequestMapping(value = "excel_export_all")
    @ResponseBody
    @SuppressWarnings("all")
    public String exportDetailExcelAll(@RequestParam Map params) {
        int[] widths = new int[] { 512*8,512*8,512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8};
        int[] styleArr = new int[] { -1,-1,-1, 1, 1, 0 , 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1,1};
        dataPermissionUtils.flowUserDataAccess(params, ModuleCodeConstant.RZSC_ALLORDER_CODE);
        List<ProductOrderDto> list = allOrderService.queryOrderList(params);
        if(list !=null && list.size()>20000){
           return SystemCommonConstant.DATA_TOO_MANY;
        }
        String sheetName  = "全部生产订单数据";
        String[] title = new String[]{"所属生产事业部","生产订单编号","订单编号","订单状态","客户","客户电话","最新完成节点","最新完成节点时间","服务合同编号","签单时间","接单时间","签单人","签单人部门","流程人员","流程人员部门","业务类型","产品","渠道","订单来源","支行","需求金额","资金用途","是否有资金业务"};
        String[] keyArray = new String[] {"productOrgName","scProductOrderNo","orderNo", "status","customerName","customerPhone","latestEndNodeName","latestEndNodeTime","contractNo","signTime","receiveOrderDate","signUserName","signUserOrgName","flowUserName","flowUserOrgName","businessProductName","productName","channelName","originCode","subBranch","loanAmount","purposeStr","isBelongRisk"};
        ExcelTool.execlExport(list,sheetName,title,keyArray,widths,styleArr);
        return "success";
    }

    /**
     * 导出(退单驳回)
     */
    @RequestMapping(value = "excel_export_rejected_t")
    @ResponseBody
    @SuppressWarnings("all")
    public void exportDetailExcelRejectedt(@RequestParam Map params) {
        int[] widths = new int[] { 512*8,512*8,512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8};
        int[] styleArr = new int[] { -1,-1,-1, 0, 1, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0};
        params.put("statusAttr",ScProductConstant.RZSCORDER_STATUS09);
        dataPermissionUtils.flowUserDataAccess(params, ModuleCodeConstant.RZSC_COMPLETE_CODE);
        List<ProductOrderDto> list = allOrderService.queryOrderList(params);
        String sheetName  = "退单驳回生产订单数据";
        String[] title = null;
        String[] keyArray = null;

        title = new String[]{"所属生产事业部","生产订单编号","订单编号","客户名称","电话号码","申请人","申请退单时间","退单原因","驳回时间","驳回原因","驳回人员","服务合同编号","签单时间","接单时间","签单人","签单人部门","流程人员","流程人员部门","业务类型","产品","渠道","支行","资金用途"};
        keyArray = new String[] {"productOrgName","scProductOrderNo","orderNo", "customerName","customerPhone","abandonUser","abandonReasonTime","abandonReason","lastRemarkTime","lastRemark","auditorName","contractNo","signTime","receiveOrderDate","signUserName","signUserOrgName","flowUserName","flowUserOrgName","businessProductName","productName","channelName","subBranch","purposeStr"};

        ExcelTool.execlExport(list,sheetName,title,keyArray,widths,styleArr);
    }

    /**
     * 导出(废单驳回)
     */
    @RequestMapping(value = "excel_export_rejected_f")
    @ResponseBody
    @SuppressWarnings("all")
    public void exportDetailExcelRejectedf(@RequestParam Map params) {
        int[] widths = new int[] { 512*8,512*8,512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8};
        int[] styleArr = new int[] { -1,-1,-1, 0, 1, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0,0};
        params.put("statusAttr",ScProductConstant.RZSCORDER_STATUS10);
        dataPermissionUtils.flowUserDataAccess(params, ModuleCodeConstant.RZSC_COMPLETE_CODE);
        List<ProductOrderDto> list = allOrderService.queryOrderList(params);
        String sheetName  = "废单驳回生产订单数据";
        String[] title = null;
        String[] keyArray = null;

        title = new String[]{"所属生产事业部","生产订单编号","订单编号","客户名称","电话号码","申请人","申请废单时间","废单原因","驳回时间","驳回原因","驳回人员","服务合同编号","签单时间","接单时间","签单人","签单人部门","流程人员","流程人员部门","业务类型","产品","渠道","支行","资金用途"};
        keyArray = new String[] {"productOrgName","scProductOrderNo","orderNo","customerName","customerPhone","abandonUser","abandonReasonTime","abandonReason","lastRemarkTime","lastRemark","auditorName","contractNo","signTime","receiveOrderDate","signUserName","signUserOrgName","flowUserName","flowUserOrgName","businessProductName","productName","channelName","subBranch","purposeStr"};
        ExcelTool.execlExport(list,sheetName,title,keyArray,widths,styleArr);
    }

    /**
     * 导出(异常订单)
     */
    @RequestMapping(value = "excel_export_abnormal")
    @ResponseBody
    @SuppressWarnings("all")
    public String exportDetailExcelAbnormal(@RequestParam Map params) {

        int[] widths = new int[] { 512*8,512*8,512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8};
        int[] styleArr = new int[] { -1,-1,-1, 0, 1, 0 , 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0};
        params.put("userLocked", "2");
        dataPermissionUtils.productOrgDataAccess(params, ModuleCodeConstant.RZSC_ABNORMALORDER_CODE);
        List<ProductOrderDto> list = allOrderService.queryOrderList(params);
        if(list !=null && list.size()>20000){
            return SystemCommonConstant.DATA_TOO_MANY;
        }
        String sheetName  = "异常订单生产订单数据";
        String[] title = new String[]{"所属生产事业部","生产订单编号","订单编号","客户名称","订单状态","当前完成节点","业务类型","产品名称","渠道","签单时间","接单时间","签单人","签单人部门","流程人员","流程人员部门","最新备注","最新备注时间","需求金额"};
        String[] keyArray = new String[] {"productOrgName","scProductOrderNo","orderNo","customerName","status","latestEndNodeName","businessProductName","productName","channelName","signTime","receiveOrderDate","signUserName","signUserOrgName","flowUserName","flowUserOrgName","lastRemark","lastRemarkTime","loanAmount"};
        ExcelTool.execlExport(list,sheetName,title,keyArray,widths,styleArr);
        return "success";
    }

    /**
     * 导出(已退单)
     */
    @RequestMapping(value = "excel_export_completed_t")
    @ResponseBody
    @SuppressWarnings("all")
    public void exportDetailExcelCompletedt(@RequestParam Map params) {

        int[] widths = new int[] { 512*8,512*8,512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8};
        int[] styleArr = new int[] { -1,-1,-1, 0, 1, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0};
        params.put("statusAttr",ScProductConstant.RZSCORDER_STATUS06);
        dataPermissionUtils.flowUserDataAccess(params, ModuleCodeConstant.RZSC_COMPLETE_CODE);
        List<ProductOrderDto> list =allOrderService.queryOrderList(params);
        String sheetName  = "已退单生产订单数据";
        String[] title = null;
        String[] keyArray = null;
        title = new String[]{"所属生产事业部","生产订单编号","订单编号","客户名称","电话号码","退单时间","退单原因","服务合同编号","签单时间","接单时间","签单人","签单人部门","流程人员","流程人员部门","业务类型","产品","渠道","支行","资金用途"};
        keyArray = new String[] {"productOrgName","scProductOrderNo","orderNo","customerName","customerPhone","abandonReasonTime","abandonReason","contractNo","signTime","receiveOrderDate","signUserName","signUserOrgName","flowUserName","flowUserOrgName","businessProductName","productName","channelName","subBranch","purposeStr"};
        ExcelTool.execlExport(list,sheetName,title,keyArray,widths,styleArr);
    }

    /**
     * 导出(已废单)
     */
    @RequestMapping(value = "excel_export_completed_f")
    @ResponseBody
    @SuppressWarnings("all")
    public void exportDetailExcelCompletedf(@RequestParam Map params) {

        int[] widths = new int[] { 512*8,512*8,512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8};
        int[] styleArr = new int[] { -1,-1,-1, 0, 1, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0};
        params.put("statusAttr",ScProductConstant.RZSCORDER_STATUS08);
        dataPermissionUtils.flowUserDataAccess(params, ModuleCodeConstant.RZSC_COMPLETE_CODE);
        List<ProductOrderDto> list =allOrderService.queryOrderList(params);
        String sheetName  = "已废单生产订单数据";
        String[] title = null;
        String[] keyArray = null;
        title = new String[]{"所属生产事业部","生产订单编号","订单编号","客户名称","电话号码","废单时间","废单原因","服务合同编号","签单时间","接单时间","签单人","签单人部门","流程人员","流程人员部门","业务类型","产品","渠道","支行","资金用途"};
        keyArray = new String[] {"productOrgName","scProductOrderNo","orderNo","customerName","customerPhone","abandonReasonTime","abandonReason","contractNo","signTime","receiveOrderDate","signUserName","signUserOrgName","flowUserName","flowUserOrgName","businessProductName","productName","channelName","subBranch","purposeStr"};
        ExcelTool.execlExport(list,sheetName,title,keyArray,widths,styleArr);
    }

    /**
     * 导出(已放款)
     */
    @RequestMapping(value = "excel_export_completed_fk")
    @ResponseBody
    @SuppressWarnings("all")
    public void exportDetailExcelCompletedfk(@RequestParam Map params) {

        int[] widths = new int[] { 512*8,512*8,512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8,512*8,512*8,512*8,512*8};
        int[] styleArr = new int[] { -1,-1,-1, 0, 1, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0};
        params.put("statusAttr", ScProductConstant.RZSCORDER_STATUS02);
        params.put("isLoan", "1");
        dataPermissionUtils.inProcessDataAccess(params, ModuleCodeConstant.RZSC_PROCESSING_CODE);
        List<ProductOrderDto> list =allOrderService.queryOrderList(params);
        String sheetName  = "已放款生产订单数据";
        String[] title = null;
        String[] keyArray = null;
        title = new String[]{"所属生产事业部","生产订单编号","订单编号","客户名称","电话号码","最新节点","最新完成节点时间","服务合同编号","签单时间","接单时间","签单人","签单人部门","流程人员","流程人员部门","业务类型","产品","渠道","支行","资金用途","需求金额","过审金额","放款时间","放款时长","还款到期日","还款时间","还款金额/每期","对外返点","渠道返点"};
        keyArray = new String[] {"productOrgName","scProductOrderNo","orderNo","customerName","customerPhone","latestEndNodeName","latestEndNodeTime","contractNo","signTime","receiveOrderDate","signUserName","signUserOrgName","flowUserName","flowUserOrgName","businessProductName","productName","channelName","subBranch","purposeStr","loanAmount","approveMoney","loanTime","loanTimeDay","repaymentDate","dateOfLoan","installmentRepayment","foreignRebates","channelRebates"};
        ExcelTool.execlExport(list,sheetName,title,keyArray,widths,styleArr);
    }

    /**
     * 导出(已完结)
     */
    @RequestMapping(value = "excel_export_completed_wj")
    @ResponseBody
    @SuppressWarnings("all")
    public void exportDetailExcelCompletewj(@RequestParam Map params) {

        int[] widths = new int[] { 512*8,512*8,512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8};
        int[] styleArr = new int[] { -1,-1,-1, 0, 1, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0,0};
        List<String> statusAttr = new ArrayList<>();
        statusAttr.add(ScProductConstant.RZSCORDER_STATUS17);
        statusAttr.add(ScProductConstant.RZSCORDER_STATUS19);
        params.put("statusAttrs",statusAttr);
        dataPermissionUtils.flowUserDataAccess(params, ModuleCodeConstant.RZSC_COMPLETE_CODE);
        List<ProductOrderDto> list =allOrderService.queryOrderList(params);
        String sheetName  = "已完结生产订单数据";
        String[] title = null;
        String[] keyArray = null;
        title = new String[]{"所属生产事业部","生产订单编号","订单编号","客户名称","电话号码","最新节点","最新完成节点时间","服务合同编号","签单时间","接单时间","签单人","签单人部门","流程人员","流程人员部门","业务类型","产品","渠道","支行","资金用途","需求金额","过审金额","放款时间","放款时长","还款到期日","还款时间","还款金额/每期","对外返点","渠道返点","完结时间"};
        keyArray = new String[] {"productOrgName","scProductOrderNo","orderNo","customerName","customerPhone","latestEndNodeName","latestEndNodeTime","contractNo","signTime","receiveOrderDate","signUserName","signUserOrgName","flowUserName","flowUserOrgName","businessProductName","productName","channelName","subBranch","purposeStr","loanAmount","approveMoney","loanTime","loanTimeDay","repaymentDate","dateOfLoan","installmentRepayment","foreignRebates","channelRebates","completedTime"};
        ExcelTool.execlExport(list,sheetName,title,keyArray,widths,styleArr);
    }



    /**
     * 导出(已完结)
     */
    @RequestMapping(value = "excel_export_completed_wj_dsh")
    @ResponseBody
    @SuppressWarnings("all")
    public void exportDetailExcelCompletewjDsh(@RequestParam Map params) {

        int[] widths = new int[] { 512*8,512*8,512*8, 512*8, 512*8, 512*8, 512*8};
        int[] styleArr = new int[] { -1,-1,-1, 0, 1, 0 , 0};
        List<UploadWjOrderDto> list =allOrderService.queryOrderListDsh(params);
        String sheetName  = "提交审核订单数据";
        String[] title = null;
        String[] keyArray = null;
        title = new String[]{"生产单号","订单编号","生产所属事业部","产品名称","提交审核时间/审核时间","提交人员/审核人员","备注/审核结果"};
        keyArray = new String[] {"scProductOrderNo","orderNo","productOrgName","productName","cretaeTime","creater_name","remark"};
        ExcelTool.execlExport(list,sheetName,title,keyArray,widths,styleArr);
    }

}
